﻿using Lee.EF.Context;
using Lee.Models.Entities;

namespace EFCoreApp;

public class EFClass
{
    public void efTest()
    {
        string _currOwner = "test"; //Console.ReadLine();//当前用户
        using var ctx = new MyDBContext();
          
        var cop = ctx.Set<Biz_Coupons>().Single(x => x.Id == 1);
        if (!string.IsNullOrEmpty(cop.Owner))
        {
            Console.WriteLine($"券被抢了");
        }
        else
        {
            cop.Owner = _currOwner;
            Thread.Sleep(5000);
            ctx.SaveChanges();
            Console.WriteLine($"恭喜{_currOwner}抢到券{cop.Id}了");
        }
        
        Console.WriteLine($"EFClass end");
    }
}